package com.tianya.scheduled.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tianya.scheduled.common.ListWrapper;
import com.tianya.scheduled.common.Page;
import com.tianya.scheduled.model.CronExpression;
import com.tianya.scheduled.mapper.CronExpressionMapper;
import com.tianya.scheduled.service.CronExpressionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tianya
 * @since 2021-05-21
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class CronExpressionServiceImpl extends ServiceImpl<CronExpressionMapper, CronExpression> implements CronExpressionService {

    @Override
    public ListWrapper<CronExpression> query(Page page) {
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<CronExpression> p =
                new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(page.getPageNum(), page.getPageSize());
        IPage<CronExpression> cronExpressionIPage = this.baseMapper.selectPage(p, new QueryWrapper<CronExpression>().eq("creator", 1));
        long total = cronExpressionIPage.getTotal();
        List<CronExpression> cronExpressions = cronExpressionIPage.getRecords();
        return ListWrapper.<CronExpression>builder()
                .list(cronExpressions)
                .total(total)
                .build();
    }
}
